home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / phone / mm2ph_send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  5.7 KB  |  205 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *     
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *     
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *     
  16.  *     
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *     
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *     
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /*                  SEND FROM PHONE TO LOCAL (SUBMIT)                   */
  36.  
  37. #include "ch.h"
  38.  
  39. extern struct ll_struct   *logptr;
  40.  
  41. mm2ph_send (curchan)                /* overall mngmt for batch of msgs    */
  42.     Chan *curchan;                /* channel being picked up            */
  43. {
  44.     short     result;
  45.     char    info[LINESIZE],
  46.             sender[LINESIZE];
  47.  
  48. #ifdef DEBUG
  49.     ll_log (logptr, LLOGBTR, "mm2ph_send (%s)", curchan -> ch_name);
  50. #endif
  51.  
  52.     if (rp_isbad (result = mm_pkinit (curchan -> ch_name)))
  53.     return (result);
  54.     if (rp_isbad (result = ph_sbinit ()))
  55.     return (result);
  56.  
  57.     while (rp_gval (result = mm_rinit (info, sender)) == RP_OK)
  58.     {
  59. #ifdef DEBUG
  60.     ll_log (logptr, LLOGPTR, "new message");
  61. #endif
  62.     if (rp_isbad (result = ph_winit (curchan -> ch_name, info, sender)))
  63.         return (result);      /* ready to process a message         */
  64.  
  65.     if (rp_isbad (result = m2p_admng ()))
  66.         return (result);      /* send the address list              */
  67.  
  68.     if (rp_isbad (result = m2p_txmng ()))
  69.         return (result);      /* send the message text              */
  70.     }
  71. #ifdef DEBUG
  72.     ll_log (logptr, LLOGPTR, "done w/msgs");
  73. #endif
  74.  
  75.     mm_pkend ();                  /* done getting messages              */
  76.     ph_sbend ();                  /* done sending messages              */
  77.  
  78.     switch (rp_gval (result))
  79.     {
  80.     case RP_DONE: 
  81.     case RP_EOF: 
  82.         return (RP_OK);
  83.     }
  84.     return (result);
  85. }
  86. /* */
  87.  
  88. LOCFUN
  89.     m2p_admng ()              /* send address list                  */
  90. {
  91.     struct rp_bufstruct thereply;
  92.     int       len;
  93.     short     result;
  94.     char    host[LINESIZE];
  95.     char    adr[LINESIZE];
  96.  
  97. #ifdef DEBUG
  98.     ll_log (logptr, LLOGPTR, "doing adrs");
  99. #endif
  100.  
  101.     FOREVER              /* iterate thru list                    */
  102.     {                  /* we already have and adr              */
  103. #ifdef DEBUG
  104.     ll_log (logptr, LLOGBTR, "new addr");
  105. #endif
  106.     result = mm_radr (host, adr);
  107.     if (rp_isbad (result))
  108.         return (result);      /* get address from Deliver           */
  109.     if (rp_gval (result) == RP_DONE)
  110.         break;          /* end of address list                */
  111.  
  112.     if (rp_isbad (result = ph_wadr (host, adr)))
  113.         return (result);      /* give to remote site                */
  114.  
  115.     if (rp_isbad (result = ph_rrply (&thereply, &len)))
  116.         return (result);      /* how did remote like it?            */
  117.  
  118.     switch (rp_gval (thereply.rp_val))
  119.                   /* was address acceptable?            */
  120.     {
  121.         case RP_AOK:       /* address ok, text not yet sent      */
  122.         mm_wrply (&thereply, len);
  123.         break;
  124.  
  125.         case RP_NO:       /* remaining acceptible responses     */
  126.         thereply.rp_val = RP_NDEL;
  127.         case RP_USER: 
  128.         case RP_NDEL: 
  129.         case RP_AGN: 
  130.         case RP_NOOP: 
  131.         mm_wrply (&thereply, len);
  132.         break;
  133.  
  134.         default:           /* responses which force abort        */
  135.         ll_log (logptr, LLOGFAT,
  136.             "adr eof reply err (%s)'%s'",
  137.             rp_valstr (thereply.rp_val), thereply.rp_line);
  138.         if (rp_isbad (thereply.rp_val))
  139.             return (thereply.rp_val);
  140.         return (RP_RPLY);
  141.     }
  142.     }
  143.     return (ph_waend ());        /* tell remote of address list end    */
  144. }
  145. /* */
  146.  
  147. LOCFUN
  148.     m2p_txmng ()              /* send message text                  */
  149. {
  150.     struct rp_bufstruct thereply;
  151.     char    buffer[BUFSIZ];
  152.     int     len;
  153.     short     result;
  154.  
  155. #ifdef DEBUG
  156.     ll_log (logptr, LLOGPTR, "doing text");
  157. #endif
  158.     len = sizeof(buffer);
  159.     while ((rp_gval (result = mm_rtxt (buffer, &len))) == RP_OK) {
  160.     if (rp_isbad (result = ph_wtxt (buffer, len)))
  161.         return (result);
  162.     len = sizeof(buffer);
  163.     }
  164. #ifdef DEBUG
  165.     ll_log (logptr, LLOGBTR, "done sending");
  166. #endif
  167.  
  168.     if (rp_isbad (result))
  169.     return (result);      /* problem with transmission          */
  170.     if (rp_gval (result) != RP_DONE)
  171.     return (RP_RPLY);      /* protocol error in reply code       */
  172.     if (rp_isbad (result = ph_wtend ()))
  173.     return (result);      /* flag end of message                */
  174.     if (rp_isbad (result = ph_rrply (&thereply, &len)))
  175.     return (result);      /* problem getting reply?             */
  176.  
  177.     switch (rp_gval (thereply.rp_val))
  178.                   /* was text acceptable?               */
  179.     {
  180.     case RP_OK: 
  181.         thereply.rp_val = RP_MOK;
  182.     case RP_MOK:           /* text was accepted                  */
  183.         mm_wrply (&thereply, len);
  184.         break;
  185.  
  186.     case RP_NO:           /* remaining acceptible responses     */
  187.         thereply.rp_val = RP_NDEL;
  188.     case RP_NDEL: 
  189.     case RP_AGN: 
  190.     case RP_NOOP: 
  191.         mm_wrply (&thereply, len);
  192.         thereply.rp_val = RP_OK;
  193.         break;                /* don't abort the process            */
  194.  
  195.     default:           /* responses which force abort        */
  196.         ll_log (logptr, LLOGFAT,
  197.             "text eof reply err (%s)'%s'",
  198.             rp_valstr (thereply.rp_val), thereply.rp_line);
  199.         if (rp_isbad (thereply.rp_val))
  200.         return (thereply.rp_val);
  201.         return (RP_RPLY);
  202.     }
  203.     return (RP_OK);
  204. }
  205.